package alogrithm;

/**
 * @author lbw
 * @version 1.0
 * @date 2021/10/16 10:47
 */
public class FindGreatestSumOfSubArray {
    public int FindGreatestSumOfSubArray(int[] array) {
        int n = array.length;
        int res = array[0];
        int tmp = array[0];
        for (int i = 1; i < n; ++i) {
            tmp += array[i];

            res = Math.max(tmp, res);
            if (tmp < 0) {
                tmp = 0;
            }
        }
        return res;
    }
}
